<template>
	<el-popover v-model="showPopoverState" trigger="hover" title="" width="640">
		<div class="flex-start-center margin-bottom-4">
			<span>生产订单</span>
		</div>
		<jk-table border :data="tableData" size="mini" :height="240">
			<vxe-column fixed="left" :width="160" align="left" field="code" title="单据编号">
				<template slot-scope="scope">
					<div class="flex-center">
						<el-button class="item-gap" size="mini" type="text" @click="onEditBtn(scope.row)">
							{{ scope.row.code }}
							<span class="el-icon-edit"></span>
						</el-button>
					</div>
				</template>
			</vxe-column>
			<vxe-column title="状态" align="left" field="openingState" :width="100">
				<template slot-scope="scope">
					<jk-state-bar :state="scope.row.serviceState" :state-list="orderStateList"></jk-state-bar>
				</template>
			</vxe-column>
			<vxe-column width="110" align="left" field="version" title="优先级">
				<template slot-scope="scope">
					<jk-state-bar :state="scope.row.priorityId" :state-list="orderPriorityList"></jk-state-bar>
				</template>
			</vxe-column>
			<vxe-column title="订单数量" align="right" field="orderQty" :min-width="100"></vxe-column>
			<vxe-column title="已下达" align="right" field="allocatedQty" :min-width="80"></vxe-column>
		</jk-table>
		<div v-show="ruleForm.id" slot="reference">
			<el-button size="mini" icon="el-icon-s-flag" class="">
				<span>生产订单：</span>
				<span style="font-weight: 700; font-size: 13px;">{{ tableData.length }}</span>
				<span> 个</span>
			</el-button>
		</div>
	</el-popover>
</template>
<script>
    import { orderPriorityList, orderStateList } from '../../../../utils/jk/status-option-list';
    import { productionPrdOrderPage } from '../../../../api/production/order';

    export default {
        components: {
        },
        props: {
            ruleForm: {
                type: Object,
                default() {
                    return {};
                }
            }
        },
        data() {
            return {
                orderPriorityList: orderPriorityList,
                orderStateList: orderStateList,
                showPopoverState: false,
                tableData: []
            };
        },
        methods: {
            onEditBtn(row) {
                this.$emit('on-leave', false);
                this.$toOtherRouter({
                    name: 'editPrdOrder',
                    query: {
                        id: row.id
                    }
                });
            },
            getListRequest() {
                if (!this.ruleForm.code) return;
                return productionPrdOrderPage({ saleOrderCode: this.ruleForm.code }).then(res => {
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                    }
                });
            }
        },
        mounted() {
            this.getListRequest();
        }
    };
</script>
